package ventanas;
/*
import beans.Abonos;
import beans.Alquileres;
import beans.Articulos;
import beans.Articulosdocumento;
import beans.Documentos;
import beans.Facturapropiedades;
import beans.Movimientokardex;
import beans.Terceros;
import interfaces.Buscadores;
import java.awt.Frame;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import managers.ManejadorArticulos;
import managers.ManejadorConfiguraciones;
import managers.ManejadorDocumentos;
import managers.Model;
import utilidades.Fechavo;

public class Formulario_Alquileres extends javax.swing.JDialog {

    /** Creates new form Formulario_Prefactura/
    Documentos d;
    Articulosdocumento ad;
    ManejadorArticulos ma;
    ManejadorDocumentos md;
    int funcion = 0;
    Buscadores b;
    DefaultTableModel mt = new DefaultTableModel() {

        public Class getColumnClass(int columnIndex) {
            if (columnIndex == 7) {
                return Boolean.class;
            } else if (columnIndex == 8) {
                return Integer.class;
            } else {
                return Object.class;
            }
        }
    };
    DefaultTableModel mtabonos = new DefaultTableModel();

    Model m;
    Frame parent;
    ManejadorConfiguraciones mc;

    public Formulario_Alquileres(Frame parent, boolean modal, Model m, Buscadores b) {

        super(parent, modal);
        this.m = m;
        this.parent = parent;
        ma = new ManejadorArticulos(m);
        md = new ManejadorDocumentos(m);
        mc = new ManejadorConfiguraciones(m);
        this.b = b;

        d = new Documentos();
        init();
        Terceros t = md.getTercero("1");
        if (t != null) {
            d.setTerceros(t);
            tercero.setText(t.getNombre());
            ntercero.setText(t.getNombre());
        } else {
            JOptionPane.showMessageDialog(null, "no se ha establecido un cliente por mostrador");
            guardar.setEnabled(false);
        }


        int ano = Calendar.getInstance().get(Calendar.YEAR);
        int mes = Calendar.getInstance().get(Calendar.MONTH) + 1;
        int dia = Calendar.getInstance().get(Calendar.DATE);

        fecha.setText(ano + "-" + mes + "-" + dia);

        Facturapropiedades fp = mc.getFacturaporpiedades("1");
        if (fp != null) {
            int consecutivo = fp.getNumeroactual() + 1;
            numero.setText(consecutivo + "");
        } else {
            JOptionPane.showMessageDialog(null, "no se ha Configuarado las propiedades de la factura");
            guardar.setEnabled(false);
        }

        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public void init() {

        initComponents();
        tab.remove(panelabonos);
        setTitle(" Punto de Ventas ");
        mt.addColumn("Codigo");
        mt.addColumn("Descripcion");
        mt.addColumn("Cantidad");
        mt.addColumn("Vlr Unit");
        mt.addColumn("Vlr Par");
        mt.addColumn("Fecha Ini");
        mt.addColumn("Fecha Fin");
        mt.addColumn("Reintegrar");
        mt.addColumn("Reintegro");
        tabla.setModel(mt);

        utilidades.FormatoNumeros fn = new utilidades.FormatoNumeros(descuento);
        descuento.addKeyListener(fn);
        descuento.addFocusListener(fn);
    }

    public Formulario_Alquileres(Frame parent, boolean modal, Documentos d, Model m, Buscadores b) {

        super(parent, modal);
        this.m = m;
        this.parent = parent;
        ma = new ManejadorArticulos(m);
        md = new ManejadorDocumentos(m);
        mc = new ManejadorConfiguraciones(m);
        this.b = b;
        this.d = d;

        init();
        llenar();
        if (tabla.getRowCount() > 0) {
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "Todos los Articulos Han sido Reintegrados");
            this.dispose();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        fecha = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        numero = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        salir = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        tab = new javax.swing.JTabbedPane();
        panel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        total = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        nota = new javax.swing.JTextField();
        subtotal = new javax.swing.JTextField();
        descuento = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        tipodescuento = new javax.swing.JComboBox();
        desposito = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        seleccionar = new javax.swing.JButton();
        quitar = new javax.swing.JButton();
        panelabonos = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaabonos = new javax.swing.JTable();
        totalpagado = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        saldo = new javax.swing.JLabel();
        guardar = new javax.swing.JButton();
        tercero = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        ntercero = new javax.swing.JTextField();
        tipod = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        estado = new javax.swing.JLabel();

        setTitle("Ventas");

        jPanel2.setBackground(new java.awt.Color(153, 205, 255));

        fecha.setEditable(false);

        jLabel4.setText("Fecha");

        numero.setEditable(false);
        numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroActionPerformed(evt);
            }
        });
        numero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroKeyTyped(evt);
            }
        });

        jLabel2.setText("Numero");

        salir.setBackground(new java.awt.Color(0, 153, 255));
        salir.setFont(new java.awt.Font("Tahoma", 1, 11));
        salir.setForeground(new java.awt.Color(0, 51, 153));
        salir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/bulletCritical.png"))); // NOI18N
        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });

        jLabel1.setBackground(new java.awt.Color(0, 153, 255));
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setForeground(new java.awt.Color(0, 51, 153));

        panel.setBackground(new java.awt.Color(212, 233, 255));

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Descripcion", "Cantidad", "Vlr Unit", "Vlr Par", "Fecha Ini", "Fecha Fin", "Reintegar", "Reintegro"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaMouseClicked(evt);
            }
        });
        tabla.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tablaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(tabla);

        total.setFont(new java.awt.Font("Tahoma", 1, 24));
        total.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        total.setText("0.00");

        jLabel11.setText("Nota");

        nota.setEnabled(false);

        subtotal.setEditable(false);
        subtotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        subtotal.setText("0.00");

        descuento.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        descuento.setText("0.00");
        descuento.setEnabled(false);
        descuento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                descuentoKeyReleased(evt);
            }
        });

        jLabel13.setText("Subtotal");

        jLabel14.setText("Descuento");

        tipodescuento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "%", "$" }));
        tipodescuento.setEnabled(false);
        tipodescuento.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                tipodescuentoItemStateChanged(evt);
            }
        });

        desposito.setEditable(false);
        desposito.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        desposito.setText("0.00");

        jLabel17.setText("Deposito");

        seleccionar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ok.png"))); // NOI18N
        seleccionar.setText("Seleccionar Todo");
        seleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seleccionarActionPerformed(evt);
            }
        });

        quitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/bulletCritical.png"))); // NOI18N
        quitar.setText("Quitar Todo");
        quitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelLayout.createSequentialGroup()
                                .addComponent(nota, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13))
                            .addGroup(panelLayout.createSequentialGroup()
                                .addComponent(desposito, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 460, Short.MAX_VALUE)
                                .addComponent(tipodescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel14)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(descuento, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(subtotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 887, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 887, Short.MAX_VALUE)
                    .addComponent(total, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addComponent(seleccionar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(quitar, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(total)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(seleccionar)
                    .addComponent(quitar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(nota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(descuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(tipodescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(panelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(desposito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17))
                        .addContainerGap())))
        );

        tab.addTab("Detalles", panel);

        panelabonos.setBackground(new java.awt.Color(212, 233, 255));

        tablaabonos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Fecha", "Valor"
            }
        ));
        jScrollPane2.setViewportView(tablaabonos);

        totalpagado.setFont(new java.awt.Font("Tahoma", 1, 14));
        totalpagado.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        totalpagado.setText("0.00");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel16.setText("Total");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel15.setText("Saldo");

        saldo.setFont(new java.awt.Font("Tahoma", 1, 18));
        saldo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        saldo.setText("0.00");

        javax.swing.GroupLayout panelabonosLayout = new javax.swing.GroupLayout(panelabonos);
        panelabonos.setLayout(panelabonosLayout);
        panelabonosLayout.setHorizontalGroup(
            panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelabonosLayout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelabonosLayout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(saldo, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelabonosLayout.createSequentialGroup()
                            .addComponent(jLabel16)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(totalpagado, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 761, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelabonosLayout.setVerticalGroup(
            panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelabonosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(saldo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(panelabonosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalpagado)
                    .addComponent(jLabel16))
                .addContainerGap(85, Short.MAX_VALUE))
        );

        tab.addTab("Abonos", panelabonos);

        guardar.setBackground(new java.awt.Color(0, 153, 255));
        guardar.setFont(new java.awt.Font("Tahoma", 1, 11));
        guardar.setForeground(new java.awt.Color(0, 51, 153));
        guardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ok.png"))); // NOI18N
        guardar.setText("Reintegrar");
        guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarActionPerformed(evt);
            }
        });

        tercero.setEnabled(false);
        tercero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                terceroActionPerformed(evt);
            }
        });

        jLabel10.setText("Cliente");

        ntercero.setEditable(false);

        tipod.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Factura", "Cotizacion" }));
        tipod.setEnabled(false);
        tipod.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                tipodItemStateChanged(evt);
            }
        });
        tipod.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tipodInputMethodTextChanged(evt);
            }
        });

        jLabel12.setText("Tipo de Documento");

        estado.setFont(new java.awt.Font("Tahoma", 1, 14));
        estado.setForeground(new java.awt.Color(255, 0, 51));
        estado.setText("         ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(187, 187, 187)
                        .addComponent(jLabel1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(estado)
                        .addGap(101, 101, 101)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(tipod, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tercero, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ntercero))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(329, 329, 329)
                        .addComponent(guardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(salir, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tab, javax.swing.GroupLayout.PREFERRED_SIZE, 912, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(estado)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(tipod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tercero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10)
                            .addComponent(ntercero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tab, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salir)
                    .addComponent(guardar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void numeroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroKeyTyped
        // TODO add your handling code here:
        if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
}//GEN-LAST:event_numeroKeyTyped

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        // TODO add your handling code here:
        this.dispose();

}//GEN-LAST:event_salirActionPerformed

    private void guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarActionPerformed
        // TODO add your handling code here:
        boolean sw = true;
        List l = getSeleccion();
        if (sw) {
            if (l.size() > 0) {
                if (Formulario_Multa_Conciliacion.Conciliar(parent, true, b, m, l, d, v)) {
                    this.dispose();
                }
            } else {
                reintegrar();
            }
        }

}//GEN-LAST:event_guardarActionPerformed

    public void reintegrar() {
        for (int i = 0; i < tabla.getRowCount(); i++) {

            if (tabla.getValueAt(i, 0) instanceof Alquileres) {
                Alquileres al = (Alquileres) tabla.getValueAt(i, 0);
                Boolean sw = (Boolean) tabla.getValueAt(i, 7);
                if (sw) {
                    al.setEstado(2);
                    md.modificar(al);
                }

            }

            this.dispose();
            JOptionPane.showMessageDialog(null, "Articulos Reintegrados con Exito");
        }
    }

    public void guardar() {

        List<Alquileres> lal = new LinkedList();
        List<Alquileres> inconsistentes = new LinkedList();
        if (d.getAlquileresCollection() != null) {
            for (int i = 0; i < d.getAlquileresCollection().size(); i++) {
                md.eliminar(d.getAlquileresCollection().get(i));
            }
        }

        for (int i = 0; i < tabla.getRowCount(); i++) {

            if (tabla.getValueAt(i, 0) instanceof Alquileres) {
                Alquileres al = (Alquileres) tabla.getValueAt(i, 0);
                Boolean sw = (Boolean) tabla.getValueAt(i, 7);
                if (sw) {
                    al.setEstado(1);
                }
                al.setDocumento(d);
                lal.add(al);
                if (Integer.parseInt(tabla.getValueAt(i, 8) + "") < al.getCantidad()) {
                    inconsistentes.add(al);

                }
            }


        }
        if (inconsistentes.size() > 0) {
        } else {
            d.setAlquileresCollection(lal);
            md.modificar(d);
            b.buscar();
            this.dispose();
            JOptionPane.showMessageDialog(null, "Datos guardados con exito");
        }
    }

    public void guardarCotizacion() {

        List<Articulosdocumento> la = new LinkedList();
        List<Movimientokardex> lmk = new LinkedList();

        if (d.getArticulosdocumentoCollection() != null) {
            for (int i = 0; i < d.getArticulosdocumentoCollection().size(); i++) {
                md.eliminar(d.getArticulosdocumentoCollection().get(i));
            }
        }

        for (int i = 0; i < tabla.getRowCount(); i++) {


            Articulosdocumento ad = (Articulosdocumento) tabla.getValueAt(i, 0);
            ad.setDocumento(d);
            la.add(ad);
        }

        d.setArticulosdocumentoCollection(la);

        if (funcion == 0) {
            Facturapropiedades fp = mc.getFacturaporpiedades("1");
            fp.setCotizaciones(fp.getCotizaciones() + 1);
            mc.modificar(fp);
            md.crear(d);
        } else {
            md.modificar(d);
        }

        // reiniciar();
        this.dispose();
        b.buscar();
        JOptionPane.showMessageDialog(null, "Datos guardados con exito");
    }

    public boolean validar() {
        if (numero.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, "Digite el NUMERO porfavor");
            numero.requestFocus();
            return false;
        } else if (fecha.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, "Digite la FECHA porfavor");
            fecha.requestFocus();
            return false;
        } else if (tercero.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, "Digite el PROVEEDOR porfavor");
            fecha.requestFocus();
            return false;
        } else if (tabla.getRowCount() <= 0) {
            JOptionPane.showMessageDialog(null, "Adicione al menos un Articulo a la Venta");

            return false;
        } else {
            if (d.getTipo() != 1) {
                if (!this.comprovarExitencia()) {
                    JOptionPane.showMessageDialog(null, "Los Articulos en rojo tienen una cantidad mayor a la exitencia, Editelos");
                    return false;
                }
            }
        }
        return true;
    }

    public void llenarModel() {
        List<Articulosdocumento> la = d.getArticulosdocumentoCollection();
        List<Alquileres> lal = d.getAlquileresCollection();
        if (la != null) {
            for (int i = 0; i < la.size(); i++) {
                Articulos a1 = la.get(i).getArticulo();
                int cantidades = la.get(i).getCantidad().intValue();
                mt.addRow(new Object[]{la.get(i), a1.getDescripcioncomercial(), cantidades, utilidades.FormatoNumeros.formatear(la.get(i).getVlrunitario() + ""), utilidades.FormatoNumeros.formatear(la.get(i).getVlrparcial() + "")});
                // totales+=(la.get(i).getVlrparcial());

            }
        }
        if (lal != null) {
            for (int i = 0; i < lal.size(); i++) {
                Articulos a1 = lal.get(i).getArticulo();
                int cantidades = lal.get(i).getCantidad();
                mt.addRow(new Object[]{lal.get(i), a1.getDescripcioncomercial(), cantidades, utilidades.FormatoNumeros.formatear(lal.get(i).getVlrunitario() + ""), utilidades.FormatoNumeros.formatear(lal.get(i).getTotal() + "")});
                //  totales+=(lal.get(i).getTotal());

            }
        }

    }
    int dev = 0;

    public void llenar() {
        funcion = 1;
        numero.setText(d.getNumero());
        fecha.setText(new java.text.SimpleDateFormat("yyyy-MM-dd").format(d.getFecha()));
        tercero.setText(d.getTerceros().getNit() + "");
        ntercero.setText(d.getTerceros().getNombre());
        descuento.setText(d.getDescuento() + "");
        List<Articulosdocumento> la = d.getArticulosdocumentoCollection();
        List<Alquileres> lal = d.getAlquileresCollection();
        if (d.getEstado() != null && d.getTipo() == 1) {
            if (d.getEstado() == 0) {
                estado.setText("En Deuda");
            } else {
                estado.setText("Pagada");
                guardar.setEnabled(false);

            }
        } else {
            estado.setText("");

        }
        if (d.getTipo() == 1) {
            tipod.setSelectedIndex(1);
        }

        tipodescuento.setSelectedIndex(d.getTipodescuento());
        if (d.getDescuento() != null) {
            descuento.setText(utilidades.FormatoNumeros.formatear(d.getDescuento() + ""));
        } else {
            descuento.setText("0.00");
        }
        subtotal.setText(utilidades.FormatoNumeros.formatear("" + d.getSubtotal()));
        total.setText(utilidades.FormatoNumeros.formatear(d.getTotal() + ""));


        if (lal != null) {
            for (int i = 0; i < lal.size(); i++) {
                Articulos a1 = lal.get(i).getArticulo();
                if (lal.get(i).getEstado() == 1) {
                    int cantidades = lal.get(i).getCantidad();
                    mt.addRow(new Object[]{lal.get(i),
                                a1.getDescripcioncomercial(),
                                cantidades,
                                utilidades.FormatoNumeros.formatear(lal.get(i).getVlrunitario() + ""),
                                utilidades.FormatoNumeros.formatear(lal.get(i).getTotal() + ""),
                                lal.get(i).getFechaIni(),
                                lal.get(i).getFechaFin(),
                                true,
                                cantidades});
                }
                //  totales+=(lal.get(i).getTotal());

            }
            dev = lal.size();
        }
        mtabonos = new DefaultTableModel();
        mtabonos.addColumn("Fecha");
        mtabonos.addColumn("Valor");
        if (d.getTipopago() != null) {
            if (d.getTipopago() == 3 || d.getTipopago() == 2) {
                totalpagado.setText(utilidades.FormatoNumeros.formatear(d.getTotalpagado() + ""));
                saldo.setText(utilidades.FormatoNumeros.formatear((d.getTotal() - d.getTotalpagado()) + ""));

                if (d.getAbonosList() != null) {
                    for (int i = 0; i < d.getAbonosList().size(); i++) {
                        Abonos abo = d.getAbonosList().get(i);
                        mtabonos.addRow(new Object[]{abo.getFecha(), utilidades.FormatoNumeros.formatear(abo + "")});
                    }
                }
                tab.add("Abonos", panelabonos);
                tablaabonos.setModel(mtabonos);
            }
        }
    }

    public boolean comprovarExitencia() {
        boolean sw = true;
        Vector tot = new Vector();
        for (int i = 0; i < tabla.getRowCount(); i++) {
            if (tabla.getValueAt(i, 0) instanceof Articulosdocumento) {
                Articulosdocumento ad = (Articulosdocumento) tabla.getValueAt(i, 0);
                if (ad.getCantidad() > ma.getArticulo(ad.getArticulo().getId() + "").getExistencia().longValue()) {
                    tot.add(i);
                    sw = false;
                }
            }
        }

        if (!sw) {
            int toteados[] = new int[tot.size()];
            for (int i = 0; i < tot.size(); i++) {
                toteados[i] = i;

            }
            utilidades.TablaRender tabre = new utilidades.TablaRender();
            tabre.setToteados(toteados);
            System.out.println(toteados.length);

            mt = new DefaultTableModel();
            mt.addColumn("Codigo");
            mt.addColumn("Descripcion");
            mt.addColumn("Cantidad");
            mt.addColumn("Vlr Unit");
            mt.addColumn("Vlr Par");
            tabla.setDefaultRenderer(Object.class, tabre);
            llenarModel();
            tabla.setModel(mt);
        }
        return sw;

    }
   
    private void numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroActionPerformed
        // TODO add your handling code here:
        tercero.requestFocus();
    }//GEN-LAST:event_numeroActionPerformed

    private void terceroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_terceroActionPerformed
        // TODO add your handling code here:
        if (tercero.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, "Digite el nit del Tercero ");
        } else if (md.getTercero((Object) tercero.getText()) != null) {
            d.setTerceros(md.getTercero((Object) tercero.getText()));
            tercero.setText(d.getTerceros().getNit() + "");
            ntercero.setText(d.getTerceros().getNombre());
        } else {
            JOptionPane.showMessageDialog(null, "Tercero no existe");
        }
    }//GEN-LAST:event_terceroActionPerformed

    public void reiniciar() {
        tipod.setSelectedIndex(0);
        d = new Documentos();
        mt = new DefaultTableModel();
        mt.addColumn("Codigo");
        mt.addColumn("Descripcion");
        mt.addColumn("Cantidad");
        mt.addColumn("Vlr Unit");
        mt.addColumn("Vlr Par");
        tabla.setModel(mt);
        Terceros t = md.getTercero("1");
        if (t != null) {
            d.setTerceros(t);
            tercero.setText(t.getNombre());
            ntercero.setText(t.getNombre());
        } else {
            JOptionPane.showMessageDialog(null, "no se ha establecido un cliente por mostrador");
            guardar.setEnabled(false);
        }

        int ano = Calendar.getInstance().get(Calendar.YEAR);
        int mes = Calendar.getInstance().get(Calendar.MONTH) + 1;
        int dia = Calendar.getInstance().get(Calendar.DATE);

        fecha.setText(ano + "-" + mes + "-" + dia);

        Facturapropiedades fp = mc.getFacturaporpiedades("1");
        if (fp != null) {
            int consecutivo = fp.getNumeroactual() + 1;
            numero.setText(consecutivo + "");
        } else {
            JOptionPane.showMessageDialog(null, "no se ha Configuarado las propiedades de la factura");
            guardar.setEnabled(false);
        }

        ad = null;

        descuento.setText("0.00");
        total.setText("0.00");
        subtotal.setText("0.00");
    }

    private void descuentoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_descuentoKeyReleased
        // TODO add your handling code here:
        calcularDesceunto();
    }//GEN-LAST:event_descuentoKeyReleased

    public void calcularDesceunto() {
        if (!descuento.getText().trim().equals("")) {
            double t = Double.parseDouble(subtotal.getText().replaceAll(",", ""));
            double dev = Double.parseDouble(descuento.getText().replaceAll(",", ""));
            if (tipodescuento.getSelectedIndex() == 0) {
                dev = t - dev / 100 * t;
            } else {
                dev = t - dev;
            }
            if (dev >= 0) {
                total.setText(utilidades.FormatoNumeros.formatear(dev + ""));
            }
            //}
        }
    }

    private void tipodescuentoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_tipodescuentoItemStateChanged
        // TODO add your handling code here:
        calcularDesceunto();
    }//GEN-LAST:event_tipodescuentoItemStateChanged

    private void tipodInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tipodInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_tipodInputMethodTextChanged

    private void tipodItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_tipodItemStateChanged
        // TODO add your handling code here:
        if (tipod.getSelectedIndex() == 0) {
            d.setTipo(3);
            Facturapropiedades fp = mc.getFacturaporpiedades("1");
            if (fp != null) {
                int consecutivo = fp.getNumeroactual() + 1;
                numero.setText(consecutivo + "");
            } else {
                JOptionPane.showMessageDialog(null, "no se ha Configuarado las propiedades de la factura");
                guardar.setEnabled(false);
            }
        } else {
            Facturapropiedades fp = mc.getFacturaporpiedades("1");
            if (fp != null) {
                d.setTipo(1);
                if (funcion != 1) {
                    long consecutivo = fp.getCotizaciones() + 1;
                    numero.setText(consecutivo + "");
                } else {
                    numero.setText(d.getNumero() + "");
                }

            } else {
                JOptionPane.showMessageDialog(null, "no se ha Configuarado las propiedades de la factura");
                guardar.setEnabled(false);
            }
        }
    }//GEN-LAST:event_tipodItemStateChanged

    private void tablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseClicked
        // TODO add your handling code here:
        int index = tabla.getSelectedRow();
    }//GEN-LAST:event_tablaMouseClicked

    private void seleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionarActionPerformed
        // TODO add your handling code here:
        for (int i = 0; i < tabla.getRowCount(); i++) {
            tabla.setValueAt(true, i, 7);
        }
    }//GEN-LAST:event_seleccionarActionPerformed

    private void quitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitarActionPerformed
        // TODO add your handling code here:
        for (int i = 0; i < tabla.getRowCount(); i++) {
            tabla.setValueAt(false, i, 7);
        }
    }//GEN-LAST:event_quitarActionPerformed

    private void tablaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaKeyTyped
        // TODO add your handling code here:
        System.out.print("sfsfs");
        if (this.tabla.getSelectedRow() > -1) {
            if (!Character.isDigit(evt.getKeyChar())) {
                evt.consume();
            }
        }
    }//GEN-LAST:event_tablaKeyTyped
    Vector v;

    public List<Alquileres> getSeleccion() {
        List<Alquileres> l = new LinkedList();
        v = new Vector();
        try {
            for (int i = 0; i < tabla.getRowCount(); i++) {
                Boolean sw = (Boolean) tabla.getValueAt(i, 7);
                if (sw) {
                    Alquileres a = (Alquileres) tabla.getValueAt(i, 0);
                    int ctd = Integer.parseInt("" + tabla.getValueAt(i, 2));
                    int ctd2 = Integer.parseInt("" + tabla.getValueAt(i, 8));
                    SimpleDateFormat formato = new SimpleDateFormat("yyyy/MM/dd");

                    int dias = new Fechavo().DiaMulta(formato.format(a.getFechaFin()));
                    //   System.out.println(""+ctd+"<>"+ctd2+" multas= "+formato.format(a.getFechaFin()));
                    if (ctd2 < ctd) {
                        l.add(a);
                        v.add(ctd2);
                    } else if (dias > 0) {
                        l.add(a);
                        v.add(ctd2);
                    }
                }
            }
        } catch (Exception er) {
            er.printStackTrace();
            JOptionPane.showMessageDialog(null, "Esciba solo numeros en la cantidad de reintegro");
            l = new LinkedList();
        }
        return l;
    }

    public boolean esta(Object a) {
        for (int i = 0; i < tabla.getRowCount(); i++) {
            // System.out.println("validando" +tabla.getValueAt(i, 0)+" "+(a));
            if ((tabla.getValueAt(i, 0) + "").equals(a + "")) {
                return true;
            }
        }
        return false;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField descuento;
    private javax.swing.JTextField desposito;
    private javax.swing.JLabel estado;
    private javax.swing.JTextField fecha;
    private javax.swing.JButton guardar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField nota;
    private javax.swing.JTextField ntercero;
    private javax.swing.JTextField numero;
    private javax.swing.JPanel panel;
    private javax.swing.JPanel panelabonos;
    private javax.swing.JButton quitar;
    private javax.swing.JLabel saldo;
    private javax.swing.JButton salir;
    private javax.swing.JButton seleccionar;
    private javax.swing.JTextField subtotal;
    private javax.swing.JTabbedPane tab;
    private javax.swing.JTable tabla;
    private javax.swing.JTable tablaabonos;
    private javax.swing.JTextField tercero;
    private javax.swing.JComboBox tipod;
    private javax.swing.JComboBox tipodescuento;
    private javax.swing.JLabel total;
    private javax.swing.JLabel totalpagado;
    // End of variables declaration//GEN-END:variables
}
*/